//https://www.cnblogs.com/-wenli/p/13748224.html
package main

import "github.com/gin-gonic/gin"

func main() {
    r := gin.Default() // 实例化 Default()方法会自动使用Logger和Recovery中间件

    r.GET("/ping/:name", func(c *gin.Context) { //域名后面请求路径
        // :参数为必填
        name := c.Param("name")
        c.JSON(200, gin.H{
            "code" : 200,
            "message": "pong",
            "data" : gin.H{
                "name" :name,
                "age" :12,
            },
            
        })
    })

    r.GET("/ping/:name/*action", func(c *gin.Context) { //域名后面请求路径
        // :参数为必填
        // *参数为非必填
        name := c.Param("name")
        action := c.Param("action")
        c.JSON(200, gin.H{
            "code" : 200,
            "message": "pong",
            "data" : gin.H{
                "name" :name,
                "action" :action,
                "age" :12,
            },
            
        });
        c.String(200, "Hello %s ,action %s", name,action)
    });

    r.Run(":8089") // listen and serve on 127.0.0.1:8089/ping   启动及监听那个端口
}